{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "5a0c879e",
   "metadata": {},
   "source": [
    "# WhiteNoiseFactor\n",
    "\n",
    "*Below is partly generated with ChatGPT 4o, needs to be verified.*\n",
    "\n",
    "## Overview\n",
    "\n",
    "The `WhiteNoiseFactor` in GTSAM is a binary nonlinear factor designed to estimate the parameters of zero-mean Gaussian white noise. It uses a **mean-precision parameterization**, where the mean $ \\mu $ and precision $ \\tau = 1/\\sigma^2 $ are treated as variables to be optimized."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b40b3242",
   "metadata": {},
   "source": [
    "## Parameterization\n",
    "\n",
    "The factor models the negative log-likelihood of a zero-mean Gaussian distribution as follows,\n",
    "$$\n",
    "f(z, \\mu, \\tau) = \\log(\\sqrt{2\\pi}) - 0.5 \\log(\\tau) + 0.5 \\tau (z - \\mu)^2\n",
    "$$\n",
    "where:\n",
    "- $ z $: Measurement value (observed data).\n",
    "- $ \\mu $: Mean of the Gaussian distribution (to be estimated).\n",
    "- $ \\tau $: Precision of the Gaussian distribution $ \\tau = 1/\\sigma^2 $, also to be estimated).\n",
    "\n",
    "This formulation allows the factor to optimize both the mean and precision of the noise model simultaneously."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f36abdb",
   "metadata": {},
   "source": [
    "## Use Case: Estimating IMU Noise Characteristics\n",
    "\n",
    "The `WhiteNoiseFactor` can be used in system identification tasks, such as estimating the noise characteristics of an IMU. Here's how it would work:\n",
    "\n",
    "1. **Define the Measurement**:\n",
    "   - Collect a series of IMU measurements (e.g., accelerometer or gyroscope readings) under known conditions (e.g., stationary or constant velocity).\n",
    "\n",
    "2. **Set Up the Factor Graph**:\n",
    "   - Add `WhiteNoiseFactor` instances to the factor graph for each measurement, linking the observed value $ z $ to the mean and precision variables.\n",
    "\n",
    "3. **Optimize the Graph**:\n",
    "   - Use GTSAM's nonlinear optimization tools to solve for the mean $ \\mu $ and precision $ \\tau $ that best explain the observed measurements.\n",
    "\n",
    "4. **Extract Noise Characteristics**:\n",
    "   - The optimized mean $ \\mu $ represents the bias in the sensor measurements.\n",
    "   - The optimized precision $ \\tau $ can be inverted to compute the standard deviation $ \\sigma = 1/\\sqrt{\\tau} $, which represents the noise level."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
